package com.example.demo.reflect;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

class Solution {
    public int longestSubsequence(int[] nums, int difference) {
        int n = nums.length;
        //以nums[i]为结尾的所有子序列中最长等差子序列为dp[i]
        int[] dp = new int[n];
        HashMap<Integer,Integer> map = new HashMap<>();
        Arrays.fill(dp,1);
        int res = 1;
        for(int i =0;i<n;++i) {
            map.put(nums[i],i);
            if(map.containsKey(nums[i] - difference)) {
                int j = map.get(nums[i] - difference);
                dp[i] = dp[map.get(nums[i] - difference)] + 1;
            }
            res = Math.max(res,dp[i]);
        }
        System.out.println();
        for(int i =0;i<n;++i) System.out.print(dp[i] + " ");
        return res;
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        //[7,7,7,7,7,7,7]
        //0
        int[] nums = {7,7,7,7,7,7,7};
        solution.longestSubsequence(nums,0);
    }
}
